<template>
    <div class="table">
        <h1 style="text-align: center">成绩详情</h1>
            <div class="handle-box">
                <el-input v-model="select_word" placeholder="输入关键字" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="search"  plain @click="search">搜索</el-button>
                <el-button type="primary" icon="edit" plain @click="addDogVis=true">添加成绩信息</el-button>
                <el-button type="primary" icon="el-icon-download" plain  @click="downloadfile">导出详细信息</el-button>
                <form class="form-horizontal" id="form_table"  style="margin-top: 10px" enctype="multipart/form-data">
                    <input class="drinput" type="file" name="filename"></input>
                    <button type="submit" class="drbutton" @click="imports">导入成绩信息</button>
                </form>
            </div>
            <div>
                <el-table :data="tableData" border style="width: 100%"  max-height="600">
                    <el-table-column type="index" width="55"></el-table-column>
                    <el-table-column property="subject" label="考试科目" width="120"></el-table-column>
                    <el-table-column property="place" label="考试地点" width="120"></el-table-column>
                    <el-table-column property="name" label="姓名" width="120"></el-table-column>
                    <el-table-column property="phone" label="联系方式" width="120"></el-table-column>
                    <el-table-column property="idcard" label="身份证号码"></el-table-column>
                    <el-table-column property="company" label="所在单位"></el-table-column>
                    <el-table-column property="grade" label="成绩"></el-table-column>
                    <el-table-column property="remarks" label="状态"></el-table-column>
                    <el-table-column property="sex" label="性别"></el-table-column>
                    <el-table-column property="seatnumber" label="座位号"></el-table-column>
                    <el-table-column property="testtime" label="考试时间"></el-table-column>
                    <el-table-column property="testtime" label="创建时间"></el-table-column>
                    <el-table-column property="creater" label="创建人"></el-table-column>
                    <el-table-column property="updatetime" label="修改时间"></el-table-column>
                    <el-table-column property="modifier" label="修改人"></el-table-column>
                    <el-table-column property="reason" label="修改原因"></el-table-column>
                    <el-table-column label="操作" fixed="right" width="150">
                        <template slot-scope="scope">
                            <el-button
                                size="mini" type="primary"
                                @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                            <el-button
                                size="mini"
                                type="danger"
                                @click="delOne(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination v-show="page"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="pageNum"
                    :page-size="10"
                    layout="prev, pager, next, jumper"
                    :total="count">
                </el-pagination>
                <el-pagination v-show="!page"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange1"
                    :current-page.sync="pageNum1"
                    :page-size="10"
                    layout="prev, pager, next, jumper"
                    :total="count1">
                </el-pagination>
                <el-dialog title="修改成绩" :visible.sync="updateDogVis"  size="small">
                    <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                        <el-form-item label="姓名">
                            <el-input v-model="ruleForm.name"></el-input>
                        </el-form-item>
                        <el-form-item label="联系方式">
                            <el-input v-model="ruleForm.phone"></el-input>
                        </el-form-item>
                        <el-form-item label="身份证号码">
                            <el-input v-model="ruleForm.idcard"></el-input>
                        </el-form-item>
                        <el-form-item label="所在单位">
                            <el-input v-model="ruleForm.company"></el-input>
                        </el-form-item>
                        <el-form-item label="成绩">
                            <el-input v-model="ruleForm.grade"></el-input>
                        </el-form-item>
                        <el-form-item label="状态">
                            <el-input v-model="ruleForm.remarks"></el-input>
                        </el-form-item>
                        <el-form-item label="性别">
                            <el-input v-model="ruleForm.sex"></el-input>
                        </el-form-item>
                        <el-form-item label="座位号">
                            <el-input v-model="ruleForm.seatnumber"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="handleupdata('ruleForm')">立即修改</el-button>
                            <el-button @click="resetForm('ruleForm')">重置</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
                <el-dialog title="添加成绩信息" :visible.sync="addDogVis" size="small" >
                    <el-form :model="ruleForm1"  ref="ruleForm1" label-width="100px" class="demo-ruleForm">
                        <el-form-item label="考试科目">
                            <el-input v-model="ruleForm1.subject"></el-input>
                        </el-form-item>
                        <el-form-item label="考试地点">
                            <el-input v-model="ruleForm1.place"></el-input>
                        </el-form-item>
                        <el-form-item label="姓名">
                            <el-input v-model="ruleForm1.name"></el-input>
                        </el-form-item>
                        <el-form-item label="联系方式">
                            <el-input v-model="ruleForm1.phone"></el-input>
                        </el-form-item>
                        <el-form-item label="身份证号码">
                            <el-input v-model="ruleForm1.idcard"></el-input>
                        </el-form-item>
                        <el-form-item label="所在单位">
                            <el-input v-model="ruleForm1.company"></el-input>
                        </el-form-item>
                        <el-form-item label="成绩">
                            <el-input v-model="ruleForm1.grade"></el-input>
                        </el-form-item>
                        <el-form-item label="状态">
                            <el-input v-model="ruleForm1.remarks"></el-input>
                        </el-form-item>
                        <el-form-item label="性别">
                            <el-input v-model="ruleForm1.sex"></el-input>
                        </el-form-item>
                        <el-form-item label="座位号">
                            <el-input v-model="ruleForm1.seatnumber"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="handleadd('ruleForm1')">立即添加</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div></div>

</template>

<script>
    export default {
        data() {
            return {
                tableData:[  {
                    id:'',
                    subject:'',
                    place:'',
                    name:'',
                    phone:'',
                    idcard:'',
                    company:'',
                    grade:'',
                    testtime:'',
                    createtime:'',
                    creater:'',
                    updatetime:'',
                    modifier:'',
                    reason:'',
                    remarks:'',
                    iddelete:'',
                    seatnumber:'',
                    sex:'',
                }],
                ruleForm:{
                    id:'',
                    name:'',
                    phone:'',
                    sex:'',
                    seatnumber:'',
                    remarks:'',
                    grade:'',
                    company:'',
                    idcard:'',
                },
                ruleForm1:{
                    subject:'',
                    place:'',
                    name:'',
                    phone:'',
                    sex:'',
                    seatnumber:'',
                    remarks:'',
                    grade:'',
                    company:'',
                    idcard:'',
                },
                select_word:'',
                pageNum:1,
                pageNum1:1,
                count:1,
                count1:1,
                updateDogVis:false,
                addDogVis:false,
                page:true
            }
        },
        created(){
            this.getData();
        },
        computed: {

        },
        methods: {
            downloadfile(){
                window.location.href='/text/achievement/getexcel';
            },
            getData(){
                this.$axios.get('/text/achievement/query?pageNum=1').then((res)=>{
                    this.tableData=res.data.data.list;
                    this.count=res.data.data.total;
                })
            },
            imports(){
                var zipFormData = new FormData();
                zipFormData.append('filename', this.upath);//filename是键，file是值，就是要传的文件，test.zip是要传的文件名
                this.$axios.post('/text/achievement/import', zipFormData,config).then((res)=>{

                })
            },
            handleEdit(index, row) {
                this.updateDogVis = true;
                this. ruleForm= row;
            },
            handleupdata(){
                        this.$axios.put('/text/achievement/update?' +
                            'id='+this.ruleForm.id+
                            '&name=' + this.ruleForm.name +
                            "&phone=" + this.ruleForm.phone+
                            "&sex=" + this.ruleForm.sex+
                            "&seatnumber=" + this.ruleForm.seatnumber+
                            "&remarks=" + this.ruleForm.remarks+
                            "&grade=" + this.ruleForm.grade+
                            "&company=" + this.ruleForm.company+
                            "&idcard=" + this.ruleForm.idcard
                        ).then((res) => {
                            if(res.data.code==200)
                            {
                                this.$message({
                                    message: '修改信息成功！！',
                                    type: 'success'
                                });
                            }
                            this.getData();
                            this.updateDogVis = false;
                        })
            },
            delOne(index, row) {
                this.$axios.delete('/text/achievement/deletebyid?' +
                    'id=' + row.id
                ).then((res) => {
                    this.getData();
                    this.$message.info('删除成功');
                })
            },
            search(select_word){
                this.$axios.get('/text/achievement/queryfuzzy?pageNum=1&idcard='+this.select_word).then((res) => {
                    this.count1=res.data.data.data.total;
                    this.tableData= res.data.data.data.list;
                    this.page=false
                })
            },
            handleadd() {
                        this.$axios.post('/text/achievement/create?' +
                            'subject=' + this.ruleForm1.subject +
                            '&place=' + this.ruleForm1.place +
                            '&name=' + this.ruleForm1.name +
                            "&phone=" + this.ruleForm1.phone+
                            "&sex=" + this.ruleForm1.sex+
                            "&seatnumber=" + this.ruleForm1.seatnumber+
                            "&remarks=" + this.ruleForm1.remarks+
                            "&grade=" + this.ruleForm1.grade+
                            "&company=" + this.ruleForm1.company+
                            "&idcard=" + this.ruleForm1.idcard
                        ).then((res) => {
                            if(res.data.code==200)
                            {
                                this.$message({
                                    message: '添加成功！！',
                                    type: 'success'
                                });
                            }
                            else if(res.data.code==402)
                            {
                                this.$message.error('')
                            }
                            this.getData();
                            this.addDogVis = false;
                            this.resetForm('ruleForm1')
                        })

            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(pageNum) {
                this.$axios.get('/text/achievement/query?pageNum='+pageNum).then((res)=>{
                    this.tableData=res.data.data.list
                })
            },
            handleCurrentChange1(pageNum1,select_word) {
                this.$axios.get('/text/achievement/queryfuzzy?pageNum='+pageNum1+'&idcard='+this.select_word).then((res)=>{
                    this.tableData= res.data.data.data.list;
                })
            },
        }
    }
</script>

<style scoped>
    .table{
        padding: 20px;
    }
    .handle-box{
        margin-bottom: 20px;
    }
    .handle-select{
        width: 20px;
    }
    .handle-input{
        width: 300px;
        display: inline-block;
    }
    .drbutton{
        width: 100px;
        height: 40px;
        border-radius: 5px;
        background-color: white;
    }
    .drinput{
        width: 300px;
        height: 35px;
        border-radius: 5px;
        border: 1px #d3e0e9 solid;
    }
</style>
